package com.wiz.weixin.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wiz.weixin.TO.WeixinConfigTO;
import com.wiz.weixin.mapper.WeixinConfigMapper;
import com.wiz.weixin.service.WeixinConfigService;
/**
 * 优惠
 * @author xxy
 *
 */
@Service("weixinConfigService")
public class WeixinConfigServiceImpl implements WeixinConfigService {

	@Resource
	private WeixinConfigMapper weixinConfigMapper;
	/**充值优惠*/
	@Override
	public Map<String, List<WeixinConfigTO>> listSaleInfo(List<String> list)throws Exception {
		List<WeixinConfigTO> result = weixinConfigMapper.listSaleInfo(list);
		Map<String, List<WeixinConfigTO>> map = assemblyData(result);
		return map;
	}
	/**积分活动*/
	@Override
	public Map<String, List<WeixinConfigTO>> listPointInfo(List<String> list) throws Exception {
		Map<String, List<WeixinConfigTO>> map = new HashMap<String, List<WeixinConfigTO>>();
		
		if(list == null || list.size()<=0){
			return map;
		}
		List<WeixinConfigTO> result = weixinConfigMapper.listPointInfo(list);
		map = assemblyData(result);
		return map;
	}
	/**油站介绍*/
	@Override
	public List<WeixinConfigTO> listIntroduction(List<String> list)throws Exception {
		List<WeixinConfigTO> result = new ArrayList<WeixinConfigTO>();
		if(list == null || list.size()<=0){
			return result;
		}
		result = weixinConfigMapper.listSaleInfo(list);
		return result;
	}
	/**组装数据*/
	public Map<String, List<WeixinConfigTO>> assemblyData(List<WeixinConfigTO> result)throws Exception{
		
		Map<String, List<WeixinConfigTO>> map = new HashMap<String, List<WeixinConfigTO>>();
		List<WeixinConfigTO> configList = null;
		String stationId = null;
		
		for (WeixinConfigTO bean : result) {
			stationId = bean.getHqId();
			if(map.containsKey(stationId)){
				configList = map.get(stationId);
			}else{
				configList = new ArrayList<WeixinConfigTO>();
			}
			configList.add(bean);
			map.put(stationId, configList);
		}
		return map;
	}

}
